package com.bjpowernode.javaweb.servlet;

import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

public class AServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Date nowTime=new Date();
        request.setAttribute("sysTime",nowTime);
//        Object obj=request.getAttribute("sysTime");
//        response.setContentType("text/html");
//        PrintWriter out = response.getWriter();
//        out.println(obj);

        //使用Servlet的转发机制 完成资源跳转
//        RequestDispatcher requestDispatcher = request.getRequestDispatcher("/b");
//        requestDispatcher.forward(request,response);
//        request.getRequestDispatcher("/b").forward(request,response);

        //转发到一个servlet，也可以是一个html页面
        request.getRequestDispatcher("/text.html").forward(request,response);
    }
}
